package com.logistics.receipt;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.logistics.database.Receiptdatabase;

public class receiptservlet_query extends HttpServlet {

	/**
	 * Constructor of the object.
	 */
	public receiptservlet_query() {
		super();
	}

	/**
	 * Destruction of the servlet. <br>
	 */
	public void destroy() {
		super.destroy(); // Just puts "destroy" string in log
		// Put your code here
	}
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doPost(request, response);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		response.setContentType("text/xml;charset=UTF-8");
		request.setCharacterEncoding("utf-8");
		Receiptdatabase dao= new Receiptdatabase();
		ResultSet rs;
		ArrayList<receiptInfo> array=new ArrayList<receiptInfo>();
		rs=dao.ReceiptQuery();
		try {
			while(rs.next())
			{
				receiptInfo temp=new receiptInfo();
				temp.setReceipt_id(rs.getInt("receipt_id"));
				temp.setMission_id(rs.getInt("mission_id"));
				temp.setSubstation_id(rs.getInt("substation_id"));
				temp.setMission_type(rs.getString("mission_type"));
				temp.setAddress(rs.getString("address"));
				temp.setUser_name(rs.getString("user_name"));
				temp.setProduct_name(rs.getString("product_name"));
				temp.setProduct_number(rs.getInt("product_number"));
				temp.setProduct_price(rs.getDouble("product_price"));
				temp.setReceipt_state(rs.getString("receipt_state"));
				temp.setTips(rs.getString("tips"));
				array.add(temp);
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		request.setAttribute("arr", array);
		request.getRequestDispatcher("../receipt/receipt_query.jsp").forward(request,response);
	}

	/**
	 * Initialization of the servlet. <br>
	 *
	 * @throws ServletException if an error occurs
	 */
	public void init() throws ServletException {
		// Put your code here
	}

}